/*
 * @Author: your name
 * @Date: 2021-04-28 14:07:14
 * @LastEditTime: 2021-07-28 15:58:45
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /sports-wechat-c/store/index.js
 */
/**
 * 状态管理 Vuex
 */

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    accessToken: uni.getStorageSync('accessToken') || '',
    userInfo: uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')) : {},
    position: {
      province: {},
      provinceList: [],
      city: {},
      cityList: [],
      district: {},
      districtList: [],
      lng: '',
      lat: ''
    },
    appointPlayerData: {
      list: [],
      checkedIndex: 0
    },
    // 课程搜索
    searchValue: '',
    // 活动搜索
    activityValue: '',
    // 俱乐部搜索
    clubValue: '',
    // 课程搜索历史记录
    courseList: [],
    // 活动搜索历史记录
    activityList: [],
    // 俱乐部搜索历史记录
    clubList: [],
    // 教练搜索
    coachValue:'',
    coachList:[],
		//优惠券id
    couponId:'',
    //other赛制名称
		sportName:'',
		//other赛制分类
		sportEventId:'',
		//other赛制项目
		sportObjId:'',
		//other赛制项目名称
		sportObjname:''
  },
  getters: {
    logined (state) {
      return !!state.accessToken;
    }
  },
  mutations: {
    //更新state数据
    setStateAttr (state, param) {
      if (param instanceof Array) {
        for (let item of param) {
          state[item.key] = item.val;
        }
      } else {
        state[param.key] = param.val;
      }
    },
    // 退出登录
    loginOut (state) {
      state.accessToken = ''
      state.userInfo = {}
      uni.removeStorageSync('accessToken')
      uni.removeStorageSync('userInfo')
    }
  },
  actions: {
    //更新用户信息
    async getUserInfo ({ state, commit }) {
      // const res = await request('user', 'get', {}, {
      // 	checkAuthInvalid: false
      // });
      // if(res.status === 1){
      // 	const userInfo = res.data;
      // 	commit('setStateAttr', {
      // 		key: 'userInfo',
      // 		val: userInfo
      // 	})
      // }
    },
  }
})

export default store